/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.uhk.ppro.response.web;

import cz.uhk.ppro.response.model.MobileTest;
import cz.uhk.ppro.response.model.Test;
import cz.uhk.ppro.response.service.DatabaseService;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 *
 * @author Martin
 */

@Controller
public class MobileTestController {
    
    @Autowired
    private DatabaseService databaseSession;
    
    	@RequestMapping(value="currenttestmobileresponse", method = RequestMethod.POST)
	public @ResponseBody MobileTest getTestsInJSON(
                                     //   @PathVariable String idTest
                                        @RequestParam(value="idTest",required=false) String testId
                ) {
 
              Test t = databaseSession.getTestById(Integer.parseInt(testId));
              MobileTest mobtest = new MobileTest();
              
              mobtest.addString("name", t.getName());
              mobtest.addString("desc", t.getDescr());
              mobtest.addString("number", Integer.toString(t.getQuestions().size())); //t.getQuestions().size()
              mobtest.addString("type", t.getTypes().getId().toString());
              //mobtest.setDesc(t.getDescr());
              //mobtest.setNumber(t.getQuestions().size());
              //mobtest.setType(t.getTypes().getId());
              
               return mobtest;
	}
    
    
    
    
    
    
}
